package dicky.fortunetelling.logic;

import java.util.List;

import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

public class GenChartUtil {
	public static XYMultipleSeriesDataset buildDataset(String[] titles,
			List xValues, List yValues) {
		XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

		int length = titles.length; // 有幾條線
		for (int i = 0; i < length; i++) {
			XYSeries series = new XYSeries(titles[i]); // 根據每條線的名稱創建
			double[] xV = (double[]) xValues.get(i); // 獲取第i條線的資料
			double[] yV = (double[]) yValues.get(i);
			int seriesLength = xV.length; // 有幾個點

			for (int k = 0; k < seriesLength; k++) // 每條線裡有幾個點
			{
				series.add(xV[k], yV[k]);
			}

			dataset.addSeries(series);
		}

		return dataset;
	}

	public static XYMultipleSeriesRenderer buildRenderer(int[] colors,
			PointStyle[] styles, boolean fill) {
		XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
		int length = colors.length;
		for (int i = 0; i < length; i++) {
			XYSeriesRenderer r = new XYSeriesRenderer();
			r.setColor(colors[i]);
			r.setPointStyle(styles[i]);
			r.setFillPoints(fill);
			r.setLineWidth(3);
			renderer.addSeriesRenderer(r);
		}
		return renderer;
	}

	public static void setChartSettings(XYMultipleSeriesRenderer renderer,
			String title, String xTitle, String yTitle, double xMin,
			double xMax, double yMin, double yMax, int axesColor,
			int labelsColor,int bgColor) {
		renderer.setChartTitle(title);
		renderer.setChartTitleTextSize(22);
		renderer.setXTitle(xTitle);
		
		renderer.setYTitle(yTitle);
		renderer.setXAxisMin(xMin);
		renderer.setXAxisMax(xMax);
		renderer.setYAxisMin(yMin);
		renderer.setYAxisMax(yMax);
		renderer.setZoomInLimitY(100);
		renderer.setAxesColor(axesColor);
		renderer.setLabelsColor(labelsColor);
		renderer.setBackgroundColor(bgColor);
		
		renderer.setZoomLimits(new double[] { -3,30,0,100 });
		renderer.setPanLimits(new double[] { -3,30,0,100 });
	}
}
